<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="../../configure.js"></script>
</head>
<body style="background-color: #F5F6F7">
<div class="container" style="background-color:white;margin-top: 20px">
    <form id="form" style="margin:10px 0px 10px">
        <span style="font-size:larger;color: black">修改站点</span>
        <hr style="border: black 1px solid">
        <div class="form-group">
            <label for="siteId">站点ID</label>
            <input type="text" class="form-control" name="siteId" id="siteId" placeholder="请输入站点ID">
        </div>

        <button id="find"  type="button" class="btn btn-danger form-control ">查询</button>
        <div id="success">
        <div class="form-group">
            <label for="siteName">站点名</label>
            <input type="text" class="form-control" name="siteName" id="siteName" placeholder="请输入站点名">
        </div>
        <div class="form-group">
            <label for="sitePhone">站点电话</label>
            <input type="text" class="form-control" name="sitePhone" id="sitePhone" placeholder="请输入站点电话">
        </div>
        <div data-toggle="distpicker" class="form-group">
            <label>地址 :</label>
            <select name="siteProvince"></select>
            <select name="siteCity"></select>
            <select name="siteArea"></select>
        </div>
        <button type="submit" class="btn btn-danger form-control ">修改</button>
            </div>
    </form>
</div>
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/distpicker.data.js"></script>
<script src="../js/distpicker.js"></script>
<script src="../js/distpicker.data.js"></script>
<script src="../js/distpicker.js"></script>
<script src="../layer/layer.js"></script>
<script>
    $(function(){
        $("#success").hide();
        $("#find").click(function(){
            var siteId = $("#siteId").val();
            if (siteId=="") {
                layer.msg("站点ID不能为空");
                return false
            }
            $.getJSON(url+"/admin/adminSelectSite",{siteId:siteId},function(data){
                console.log(data)
                layer.msg(data.message);
                if(data.message == "查询成功"){
                    $("#success").show();
                    $("#find").hide();
                    $("#siteName").val(data.data[0].siteName);
                    $("#proId").val(data.data[0].siteProvince);
                    $("#areId").val(data.data[0].siteArea);
                    $("#cityId").val(data.data[0].siteCity);
                    $("#sitePhone").val(data.data[0].sitePhone);
                }
                
            })
        });

        $("#form").submit(function(){
            let siteName = $("#siteName").val();
            let siteProvince = $("#proId").val();
            let siteArea = $("#areId").val();
            let siteCity = $("#cityId").val();
            let sitePhone = $("#sitePhone").val();
            let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            
            if (siteName=="") {
                layer.msg("站点名不能为空");
                return false
            }

            if (siteProvince=="") {
                layer.msg("省不能为空");
                return false
            }

            if (siteCity=="") {
                layer.msg("城市不能为空");
                return false
            }

            
            if (siteArea=="") {
                layer.msg("区域不能为空");
                return false
            }
            if (sitePhone=="") {
                layer.msg("站点联系方式不能为空");
                return false
            }else{
                if (!phoneReg.test(sitePhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }

           
            


            $.post(url+"/admin/adminUpdateSite",{
                siteName:siteName,
                siteProvince:siteProvince,
                siteArea:siteArea,
                siteCity:siteCity,
                sitePhone:sitePhone
            },function(data){
                //layer.msg(data.data.message);
                console.log(data)
                if(data.code == 1){
                    //录入成功
                    layer.msg("修改成功");
                    $("input").val("");
                    // $("input:eq(1)").val("顺丰速运");
                }else{
                    layer.msg("修改失败");
                    //录入失败
                }
            });
            return false
        });
    });
</script>
</body>
</html>